﻿<?xml version="1.0" encoding="utf-8" ?>
<DbDataRequest connection="$ForumDBConnection$" type="$ForumDBType$" defaultFormatter="bizobj Forum(lastPost(createdBy))">
  <SqlStatement hasResults="true">
    SELECT     TOP 1 id AS lastPostid, forumId AS id, lastPostDate AS lastPostdateCreated, lastPostById AS createdByid, lastPostByName AS createdByuserName,
    (SELECT     title
    FROM          ThreadPosts
    WHERE      (threadId = F.id) AND (dateCreated = F.lastPostDate) AND (createdById = F.lastPostById)) AS lastPostTitle,
    (SELECT     COUNT(title) AS Expr1
    FROM          ForumThreads
    WHERE      (forumId = F.forumId)) AS numThreads,
    (SELECT     SUM(totalPosts) AS Expr1
    FROM          ForumThreads AS ForumThreads_1
    WHERE      (forumId = F.forumId)) AS numPosts
    FROM         ForumThreads AS F
    WHERE     (forumId = @forumId)
    ORDER BY dateCreated DESC
  </SqlStatement>
  <Param name="forumId" type="UniqueIdentifier" />
</DbDataRequest>
